function out = showDataFromList(data, parameter)
% showDataFromList
%
% data -- structure; expt data, from loadDataFromList.m
% parameter -- string; field name in data
%
% TODO: important -- need to make it work for empty vectors

% gs jan 2008
% --------------------------------
disp(' ')
if nargin == 0
    disp('showDataFromList: provide a parameter name.');
    return
end

param = [];
for n = 1 : data.numCells;
    if isfield(data.cellData{n}, parameter)
        eval(['p = data.cellData{n}.' parameter ';'])
        if ~isempty(p)
            if isnumeric(p)
                if isscalar(p) % works for scalars
                    param(n) = p; %#ok<AGROW>
                elseif isvector(p)
                    try
                        param(:,n) = p; %#ok<AGROW>
                    catch % handle special cases:
                        % (1) case where the param val(s) of the 1st 
                        % through (n-1) expts was/were (scalar) NaN(s). 
                        % Solution: re-dimension previous scalar NaN(s)
                        % as vector(s) of NaNs
                        if all(isnan(param)) && isscalar(param(:,n-1))
                            numRows = max(size(p));
                            param = repmat(param, numRows, 1);
                            param(:,n) = p; %#ok<AGROW>
                        else
                            disp('showDataFromList: problem handling vector.')
                        end
                    end
                else % not yet debugged for arrays:
                    param(:,:,n) = p; %#ok<AGROW>
                end
                try % temporary -- for debugging
                if numel(size(p)) < 3
                    disp([num2str(n) '  ' data.cellData{n}.experiment '  ' ...
                        num2str(p)]);
                else
                    disp([num2str(n) '  ' data.cellData{n}.experiment '  ' ...
                        '[matrix]']);
                end
                catch
                end

            elseif ischar(p)
                disp([num2str(n) '  ' data.cellData{n}.experiment '  ' p]);
                try
                    param(n) = str2double(p); %#ok<AGROW>
                catch
                end
            end
        else % empty
            disp([num2str(n) '  ' data.cellData{n}.experiment '  ' p]);
        end
    else % the parameter didn't exist for that expt's m file
        if n == 1
            param(n) = NaN; %#ok<AGROW>
        elseif n >1
            % determine whether to use scalar or vector of NaNs
            if isscalar(param(:, n-1))
                param(n) = NaN; %#ok<AGROW>
            elseif isvector(param(:, n-1))
                param(:,n) = nan(size(param,1),1); %#ok<AGROW>
            else % presumed to be an array
                param(:,:,n) = nan(size(param,1),size(param,2),1); %#ok<AGROW>
            end
        end
        disp([num2str(n) '  ' data.cellData{n}.experiment '  -- field missing']);
    end
end
out = param;
